//文章管理
/*
 * $.fn.simpleTree;
 * @para data  json数据源
 * @para node 项目路径 ${rc.contextPath}
 * @para checked 是否显示复选框
 * @para title 网站名称
 * @para mn 一张页面重复使用时传入方法名 区分
 */

var itmeHtml;
var _articleCount = 0;
$.fn.simpleTree = function(data,node,checked,title,mn,temp){
	var dataImg = '<img src="'+node+'/images/tree/datbase.png" width="14px" height="14px"  align="bottom"/>';
	var elbow = '<img src="'+node+'/images/tree/folder.gif" style="margin-top:-2px;margin-left:20px;"/>';
	var elbow_end = '<img src="'+node+'/images/tree/folder.gif" style="margin-top:-2px;margin-left:20px;"/>';
	var ulHtml = '<ul class="ul_tree">';
	
	if(checked){
		ulHtml += '<li>'+dataImg+'<b style="font-size:13px;">'+title+'</b><b id="website_ArticleCont' +temp+ '" style="font-size:13px;"></b></li>';
	}else{
		//onclick="queryAllArticleByWebSiteId(this)" 网站下所有文章
		ulHtml += '<li >'+dataImg+'<b style="font-size:13px;">'+title+'</b><b id="website_ArticleCont' +temp+ '" style="font-size:13px;"></b></li>';
	}
	
	if(mn == undefined)
		mn = '';
	
	var arraylength = 0,arrLevel = checkLevel(data);
	$.each(data,function(i,j){
		if(j.tColumn.fcolumnlevel == arrLevel[0])
			arraylength ++;
	});

	$.each(data,function(i,u){				
			if(u.tColumn.fcolumnlevel == arrLevel[0]){//一级栏目
				arraylength -- ;
				var nodeSize = checkNode(data,u.tColumn.id);
				if(nodeSize > 0 && arraylength > 0){
					if(checked){
						ulHtml += '<li  value="'+u.tColumn.id+'"><img onclick="openTree('+u.tColumn.id+',\''+node+'\',\''+mn+'\')" id="img'+mn+u.tColumn.id+'" src="'+node+'/images/tree/node-.png" /><img id="imgFold'+mn+u.tColumn.id+'" src="'+node+'/images/tree/folder-open.gif" style="margin-top:-2px;"/><input type="checkbox" name="columnId" value="'+u.tColumn.id+'" />'+u.tColumn.fcolumnname+'('+u.articleCount+')'+'</li>';
						_articleCount+=u.articleCount;
					}else{
						ulHtml += '<li onclick="selectTree(this)"  value="'+u.tColumn.id+'"><img onclick="openTree('+u.tColumn.id+',\''+node+'\')" id="img'+u.tColumn.id+'" src="'+node+'/images/tree/node-.png" /><img id="imgFold'+u.tColumn.id+'" src="'+node+'/images/tree/folder-open.gif" style="margin-top:-2px;"/>'+u.tColumn.fcolumnname+'('+u.articleCount+')'+'</li>';
						_articleCount+=u.articleCount;
					}
					itmeHtml = '';
					ulHtml += childNodeHtml(data,nodeSize,node,u.tColumn.id,false,checked,mn);
				}else if(nodeSize > 0 && arraylength == 0){
					if(checked){
						ulHtml += '<li  value="'+u.tColumn.id+'"><img onclick="openTree('+u.tColumn.id+',\''+node+'\',\''+mn+'\')" id="img'+mn+u.tColumn.id+'" src="'+node+'/images/tree/node-.png" /><img id="imgFold'+mn+u.tColumn.id+'" src="'+node+'/images/tree/folder-open.gif" style="margin-top:-2px;"/><input type="checkbox" name="columnId" value="'+u.tColumn.id+'" />'+u.tColumn.fcolumnname+'('+u.articleCount+')'+'</li>';
						_articleCount+=u.articleCount;
					}else{
						ulHtml += '<li onclick="selectTree(this)"  value="'+u.tColumn.id+'"><img onclick="openTree('+u.tColumn.id+',\''+node+'\')" id="img'+u.tColumn.id+'" src="'+node+'/images/tree/node-.png" /><img id="imgFold'+u.tColumn.id+'" src="'+node+'/images/tree/folder-open.gif" style="margin-top:-2px;"/>'+u.tColumn.fcolumnname+'('+u.articleCount+')'+'</li>';
						_articleCount+=u.articleCount;
					}
					itmeHtml = '';
					ulHtml += childNodeHtml(data,nodeSize,node,u.tColumn.id,true,checked,mn);
				}else if(nodeSize == 0 && arraylength > 0){
					if(checked){
						ulHtml += '<li  value="'+u.tColumn.id+'">'+elbow+'<input type="checkbox" name="columnId" value="'+u.tColumn.id+'" />'+u.tColumn.fcolumnname+'('+u.articleCount+')'+'</li>';
						_articleCount+=u.articleCount;
					}else{
						ulHtml += '<li onclick="selectTree(this)" value="'+u.tColumn.id+'">'+elbow+u.tColumn.fcolumnname+'('+u.articleCount+')'+'</li>';
						_articleCount+=u.articleCount;
					}
				}else if(nodeSize == 0 &&  arraylength == 0){
					if(checked){
						ulHtml += '<li value="'+u.tColumn.id+'">'+elbow_end+'<input type="checkbox" name="columnId" value="'+u.tColumn.id+'" />'+u.tColumn.fcolumnname+'('+u.articleCount+')'+'</li>';
						_articleCount+=u.articleCount;
					}else{
						ulHtml += '<li onclick="selectTree(this)" value="'+u.tColumn.id+'">'+elbow_end+u.tColumn.fcolumnname+'('+u.articleCount+')'+'</li>';
						_articleCount+=u.articleCount;
					}
				}
				
			}	
	});
	ulHtml += '</ul>';
	return ulHtml;
};
//栏目级数
function checkLevel(data){
	var arr = [] , res = false;
	$.each(data,function(i,u){
		for(var tem = 0,len = arr.length; tem < len; tem ++){
			if(arr[tem] == u.tColumn.fcolumnlevel){
				res = true;
			}
		}
		if(!res){
			arr.push(u.tColumn.fcolumnlevel);
			res = false;
		}
	});
	return arr;
}
/////子栏目数量
function checkNode(data,tcId){
	var node = 0;
	$.each(data,function(i,u){
		if(u.tColumn.fcolumngp == tcId && u.tColumn.id != tcId){
			node ++;
		}
	});
	return node;
}

/////子栏目
function childNodeHtml(data,size,node,tcid,end,checked,mn){
	if(mn == undefined)
		mn = '';
	var childchildNode;
	//alert(tcid);
	itmeHtml += '<ul id="node'+mn+tcid+'" class="ul_tree_node" style="display:block;">';
	$.each(data,function(i,u){
		
		if(u.tColumn.fcolumngp == tcid && u.tColumn.id != tcid){
			size --;
			childchildNode =  checkNode(data,u.tColumn.id);
						
			var	marginleft = eval((u.tColumn.fcolumnlevel - 1)  * 16);
			
			if(size > 0){
				if(childchildNode > 0){//子栏目下还有子栏目
					if(checked){
						itmeHtml += '<li  value="'+u.tColumn.id+'"><img  style="margin-left:'+marginleft+'px;" onclick="openTree('+u.tColumn.id+',\''+node+'\',\''+mn+'\')" id="img'+mn+u.tColumn.id+'" src="'+node+'/images/tree/node-.png" /><img id="imgFold'+mn+u.tColumn.id+'" src="'+node+'/images/tree/folder-open.gif" style="margin-top:-2px;"/><input type="checkbox" name="columnId" value="'+u.tColumn.id+'" />'+u.tColumn.fcolumnname+'('+u.articleCount+')'+'</li>';
						_articleCount+=u.articleCount;
					}else{
						itmeHtml += '<li onclick="selectTree(this)"  value="'+u.tColumn.id+'"><img  style="margin-left:'+marginleft+'px;" onclick="openTree('+u.tColumn.id+',\''+node+'\')" id="img'+u.tColumn.id+'" src="'+node+'/images/tree/node-.png" /><img id="imgFold'+u.tColumn.id+'" src="'+node+'/images/tree/folder-open.gif" style="margin-top:-2px;"/>'+u.tColumn.fcolumnname+'('+u.articleCount+')'+'</li>';
						_articleCount+=u.articleCount;
					}
					//itmeHtml += '<li  value="'+u.id+'"><img src="'+node+'/images/tree/elbow-line.gif" /><img onclick="openTree('+u.id+',\''+node+'\',false)" id="img'+u.id+'" src="'+node+'/images/tree/elbow-minus.gif"  style="margin-left:'+marginleft+'px;"/><img id="imgFold'+u.id+'" src="'+node+'/images/tree/folder-open.gif" style="margin-top:-2px;"/>'+u.tColumn.fcolumnname+'('+u.articleCount+')'+'</li>';
					childNodeHtml(data,childchildNode,node,u.tColumn.id,false,checked,mn);
				}else{
					if(checked){
						itmeHtml += '<li  value="'+u.tColumn.id+'">'+'<img src="'+node+'/images/tree/folder.gif" style="margin-top:-2px;margin-left:'+ eval(marginleft + 20)+'px;"/>'+'<input type="checkbox" name="columnId" value="'+u.tColumn.id+'" />'+u.tColumn.fcolumnname+'('+u.articleCount+')'+'</li>';
						_articleCount+=u.articleCount;
					}else{
						itmeHtml += '<li onclick="selectTree(this)" value="'+u.tColumn.id+'">'+'<img src="'+node+'/images/tree/folder.gif" style="margin-top:-2px;margin-left:'+ eval(marginleft + 20)+'px;"/>'+u.tColumn.fcolumnname+'('+u.articleCount+')'+'</li>';
						_articleCount+=u.articleCount;
					}
				}
			}else{
				if(childchildNode > 0){//子栏目下还有子栏目
					if(checked){
						itmeHtml += '<li value="'+u.tColumn.id+'"><img  style="margin-left:'+marginleft+'px;" onclick="openTree('+u.tColumn.id+',\''+node+'\',\''+mn+'\')" id="img'+mn+u.tColumn.id+'" src="'+node+'/images/tree/node-.png" /><img id="imgFold'+mn+u.tColumn.id+'" src="'+node+'/images/tree/folder-open.gif" style="margin-top:-2px;"/><input type="checkbox" name="columnId" value="'+u.tColumn.id+'" />'+u.tColumn.fcolumnname+'('+u.articleCount+')'+'</li>';
						_articleCount+=u.articleCount;
					}else{
						itmeHtml += '<li onclick="selectTree(this)" value="'+u.tColumn.id+'"><img  style="margin-left:'+marginleft+'px;" onclick="openTree('+u.tColumn.id+',\''+node+'\')" id="img'+u.tColumn.id+'" src="'+node+'/images/tree/node-.png" /><img id="imgFold'+u.tColumn.id+'" src="'+node+'/images/tree/folder-open.gif" style="margin-top:-2px;"/>'+u.tColumn.fcolumnname+'('+u.articleCount+')'+'</li>';
						_articleCount+=u.articleCount;
					}
					childNodeHtml(data,childchildNode,node,u.tColumn.id,true,checked,mn);
				}else{
					if(checked){
						itmeHtml += '<li value="'+u.tColumn.id+'">'+'<img src="'+node+'/images/tree/folder.gif" style="margin-top:-2px;margin-left:'+eval(marginleft + 20)+'px;"/>'+'<input type="checkbox" name="columnId" value="'+u.tColumn.id+'" />'+u.tColumn.fcolumnname+'('+u.articleCount+')'+'</li>';
						_articleCount+=u.articleCount;
					}else{
						itmeHtml += '<li onclick="selectTree(this)" value="'+u.tColumn.id+'">'+'<img src="'+node+'/images/tree/folder.gif" style="margin-top:-2px;margin-left:'+eval(marginleft + 20)+'px;"/>'+u.tColumn.fcolumnname+'('+u.articleCount+')'+'</li>';
						_articleCount+=u.articleCount;
					}
				}
			}
		}
	});
	itmeHtml += '</ul>';
	return itmeHtml;
}
///节点开关控制
function openTree(uid,node,mn){
	if(mn == undefined)
		mn = '';
	//alert(uid + mn);
	var disp = document.getElementById('node'+mn+uid);
	if(disp.style.display == 'block'){
		disp.style.display = 'none';
		document.getElementById('img'+mn+uid).src = node + '/images/tree/node+.png';
		document.getElementById('imgFold'+mn+uid).src = node + '/images/tree/folder.gif';
	}else{
		disp.style.display = 'block';
		document.getElementById('img'+mn+uid).src = node + '/images/tree/node-.png';
		document.getElementById('imgFold'+mn+uid).src = node + '/images/tree/folder-open.gif';
	}
}
/***
 * 根据栏目查询
 * @param obj
 */
var liObj;
function selectTree(obj){
	liObj = obj;
	
	$(".ul_tree").find("li").removeClass();
	obj.className = 'on_li';
	//alert(obj.value);
//	$("#dataGrid").val('<tr class="tr"><td colspan="8"><img src="${rc.contextPath}/images/preload.gif" /></td></tr>');
	queryTcolSource(1);
}

//根据栏目ID 查询文章
var queryURL = '';
var queryType = 1;
var ck_state,farticleid = 1;
function queryTcolSource(type){
	///alert($("#check_state").val());
	whereName = false;
	$("#webName").hide();
	
	var fcolumnid = null;
	
	if($("#check_state").val() == 2 && liObj == null){
		$.growlUI('请先选择栏目');
		return;
	}
	_waiting._show();
	if(type == 1){
		fcolumnid = liObj.value;
//		$("#insertList_img").show();
//		$("#orderList_img").show();
		$("#order_type").show();
	}else if(type == "freequery"){
		$("#insertList_img").hide();
		$("#orderList_img").hide();
		$("#order_type").hide();
		liObj = null;
	}
		
	$("#start").val(0);
	queryURL = 'articleByColumidSource';
	queryType = 1;
	
	ck_state = $("#check_state").val();
	if($("#check_state").val() == 2){
		ck_state = $("#checkType").val();
	}
	$("#articleByCid_form").ajaxSubmit({
		url:'articleByColumidSource',
		type:'post',
		data:{'fcolumnid':fcolumnid,'check_state':ck_state,'farticleid':farticleid},
		dataType:'json',
		success:function(data){
			page(data.count,$("#limit").val(),1,"pagePanel","gotoPage",true,"queryTcolSource(1);","limit");
			bindGrid(data);
		},
		error:function(msg){
			$.growlUI('数据出错');
			_waiting._hide();
		}
	});
}

//数据排序
function order_source(obj,local){
	if(liObj == null) return;
	
	if(farticleid == 1){
		farticleid = 0;
		obj.src = local + "/images/down_list.gif";
	}else{
		farticleid = 1;
		obj.src = local + "/images/up_list.gif";
	}
	queryTcolSource(1);
}

////查询网站下的所有文章
function queryAllArticleByWebSiteId(obj){
	
	whereName = false;
	$("#webName").hide();
	
	var wid = $("#select_web").val();
	$("#start").val(0);
	_waiting._show();
	if(wid != '' || wid != null){
		if(obj != undefined){
			$(".ul_tree").find("li").removeClass();
			obj.className = 'on_li';
		}	
		
		queryURL = 'webSiteAllArticle?fsiteid='+wid;
		queryType = 3;
		
		var data = {'fsiteid':wid,'start':0,'limit':$("#limit").val()};
		if($("#check_state").val() == 2 ){
			data = {'fsiteid':wid,'start':0,'limit':$("#limit").val(),'fchecked':$("#check_state").val()};
		}
		
		$.ajax({
			url:'webSiteAllArticle',
			data:data,
			type:'post',
			dataType:'json',
			success:function(data){
				page(data.count,$("#limit").val(),1,"pagePanel","gotoPage",true,'queryAllArticleByWebSiteId();','limit');
				bindGrid(data);
			},
			error:function(msg){
				$.growlUI('数据出错');
				_waiting._hide();
			}
		});
	}else{
		$.growlUI('请先选择网站');
	}
	
}
var whereName = false;
//按条件查询文章信息
function queryArticleByArticleRequest(){
	
	whereName = true;
	
	var tcolid = null;
	if(liObj != undefined && liObj != null)
		tcolid = liObj.value;
	_waiting._show();
	$("#start").val(0);
	queryURL = 'queryArticleByArticleRequestSource';
	queryType = 2;
	/**/
	var aname,startTime,endTime,fclassid,ftypeid,addPersion;
	if($("#startTime").val() != '')
		startTime = $("#startTime").val();
	if($("#aname").val() != '')
		aname = $("#aname").val();
	if($("#endTime").val() != '')
		endTime = $("#endTime").val();
	if($("#fclassid").val() != '')
		fclassid = $("#fclassid").val();
	if($("#ftypeid").val() != '')
		ftypeid = $("#ftypeid").val();
	if($("#addPersion").val() != '')
		addPersion = $("#addPersion").val();
	/**/
	var data = {'tcolumnId':tcolid,'check_state':$("#check_state").val(),'aname':aname,'startTime':startTime,'endTime':endTime,'fclassid':fclassid,'ftypeid':ftypeid,'addPersion':addPersion};
	$("#articleByCid_form").ajaxSubmit({
		url:'queryArticleByArticleRequestSource',
		type:'post',
		data:data,
		dataType:'json',
		success:function(data){
			
			$("#webName").show();
			
			page(data.count,$("#limit").val(),1,"pagePanel","gotoPage",true,"queryArticleByArticleRequest()","limit");
			bindGrid(data);
		},
		eror:function(msg){
			$.growlUI('数据出错');
			_waiting._hide();
		}
	});
}
function gotoPage(start){
	$("#start").val(start);
	_waiting._show();
	
	var tcolid = null,data;
	if(liObj != undefined && liObj != null)
		tcolid = liObj.value;
	
	if(queryType == 1){
		data = {'fcolumnid':tcolid,'check_state':ck_state,'farticleid':farticleid,'start':start,'limit':$("#limit").val()};
	}else if(queryType == 2){
		var aname,startTime,endTime,fclassid,ftypeid,addPersion;
		if($("#startTime").val() != '')
			startTime = $("#startTime").val();
		if($("#aname").val() != '')
			aname = $("#aname").val();
		if($("#endTime").val() != '')
			endTime = $("#endTime").val();
		if($("#fclassid").val() != '')
			fclassid = $("#fclassid").val();
		if($("#ftypeid").val() != '')
			ftypeid = $("#ftypeid").val();
		if($("#addPersion").val() != '')
			addPersion = $("#addPersion").val();
		data = {'tcolumnId':tcolid,'check_state':$("#check_state").val(),'aname':aname,'startTime':startTime,'endTime':endTime,'fclassid':fclassid,'ftypeid':ftypeid,'addPersion':addPersion,'start':start,'limit':$("#limit").val()};
	}else{
		data = {'start':start,'limit':$("#limit").val()};
	}
	$("#articleByCid_form").ajaxSubmit({
		url:queryURL,
		type:'post',
		data:data,
		dataType:'json',
		success:function(data){
			bindGrid(data);
		},
		error:function(msg){
			$.growlUI('数据加载出错！');
			_waiting._hide();
		}
	});
}
function bindGrid(data){
	$("#totalCount").html('总共找到：'+data.count+'条数据');
	var num = $("#start").val();
	var html = '';
	if(data.source != ''){
		
		//
		if(data.orderType != "" && data.orderType == "insertList"){
			if(document.getElementById("order_type") != null){
				document.getElementById("order_type")[0].selected = "selected";
				$("#insertList_img").show();
				$("#orderList_img").hide();
			}
		}else if(data.orderType != "" && data.orderType == "orderList"){
			if(document.getElementById("order_type") !=null)
				document.getElementById("order_type")[1].selected = "selected";
			$("#insertList_img").hide();
			$("#orderList_img").show();
		}
		var fsArr,aclass = "";
		$.each(data.source,function(i,u){
			num ++;
			
			if(data.articletype != '' && u.ftypeid != ''){
				$.each(data.articletype,function(n,m){
					if(m.id == u.ftypeid){
						aclass = m.ftypename;
					}
				});
			}
			
			var line = '<tr id="tr'+u.id+'"  class="tr"><td><input type="checkbox" onclick="dblCkBox('+u.id+')" name="articleId" id="articleId'+u.id+'" value="'+u.id+'"/></td>';
				line += '<td onclick="trCk('+u.id+')">'+num+'</td>';
				line += '<td onclick="trCk('+u.id+')" style="text-align:left;">';
				
				if(aclass == "全屏视频" || aclass == "视频"){
					if(u.fresourceid != null || u.fresourceid != undefined){
						line += "<a href='javascript:void(0)' onclick='getPlayAddress(this,"+ u.fresourceid +")' >" + u.ftitle + "</a>";
					}else{
						line += u.ftitle;
					}
						
				}else{
					line += u.ftitle;
				}
				
				if(u.fsummary != '' && u.fsummary != undefined){
					fsArr = u.fsummary.split(";");
					for(var f=0;f<fsArr.length;f++){
						if(fsArr[f] == '<img src="/CMS/images/video.png" />'){
							line += '<img src="/CMS/images/video.png" />';
						}
						if(fsArr[f] == '<img src="/CMS/images/it.gif" />'){
							line += '<img src="/CMS/images/it.gif" />';
						}
						if(fsArr[f] == '【视频】'){
							line += '【视频】';
						}
						if(fsArr[f] == '【图文】'){
							line += '【图文】';
						}
						if(fsArr[f] != '' && fsArr[f] != '<img src="/CMS/images/video.png" />'
							&& fsArr[f] != '<img src="/CMS/images/it.gif" />'
								&& fsArr[f] != '【视频】' && fsArr[f] != '【图文】'){
							line += fsArr[f];
						}
					}
					
				}
				
				
				
				line += '</td>';
				
				//类型
				line += '<td onclick="trCk('+u.id+')">'+ aclass +'</td>';
				
				if(data.articleclass != '' && u.fclassid != ''){
					$.each(data.articleclass,function(o,p){
						if(p.id == u.fclassid)
						   line += '<td onclick="trCk('+u.id+')">'+p.fclassname+'</td>';
					});
				}else{
					line += '<td onclick="trCk('+u.id+',1,\'\')"></td>';
				}
				if(u.fchecked == 0){
					line += '<td onclick="trCk('+u.id+')">通过</td>';
				}else if(u.fchecked == 2){
					line += '<td onclick="trCk('+u.id+')">未审核</td>';
				}else if(u.fchecked == 1){
					line += '<td onclick="trCk('+u.id+')">不通过</td>';
				}
				
				line += '<td onclick="trCk('+u.id+')">'+u.faddperson+'</td>';
				line += '<td onclick="trCk('+u.id+')">'+u.faddtime+'</td>';
				if(whereName){
					line += '<td onclick="trCk('+u.id+')">'+u.webName+'</td>';
				}
				line += '</tr>';
			html += line;	
		});
	}else{
		html += '<tr class="tr"><td colspan="8">暂时无数据</td></tr>';
	}
	$("#dataGrid").html(html);
	_waiting._hide();
}
/*视频点播地址*/
function getPlayAddress(obj,rid){
	$.ajax({
		url:'loadResourceUrl?resid='+rid,
		type:'post',
		dataType:'json',
		success:function(data){
			var url;
			if(data != null){
				if(data.fmediatype == "TS"|"ts"){
					url = fuckplay.ip.rtsp + data.fresourceurl;
				}else{
					url = fuckplay.ip.http + data.fresourceurl;
				}
				var x = $(obj).offset().left + $(obj).width();
				var y = $(obj).offset().top - ($("#show_play_add").height()/2);
				$("#show_play_add").animate({left:x + 'px',top:y + 'px'});
				$("#show_play_add").show();
				
				$("#play_html").html("播放地址："+url);
			}
		},
		error:function(msg){
			$.growlUI('加载出错');
		}
	});
}


/*选中*/
function dblCkBox(id){
		if(document.getElementById('articleId'+id).checked){
			$("#tr"+id).css('backgroundColor','#D8F79D');
		}else{
			$("#tr"+id).css('backgroundColor','#ffffff');
		}
}
function trCk(id){
	$("input[type='checkbox'][name='articleId']:checked").each(function(){
		$(this).attr('checked',false);
		var tid = $(this).val();
		$("#tr" + tid).css('backgroundColor','#ffffff');
	});
	
//	if(document.getElementById('articleId'+id).checked){
//		document.getElementById('articleId'+id).checked = false;
//		$("#tr"+id).css('backgroundColor','#ffffff');
//	}else{
		document.getElementById('articleId'+id).checked = true;
		$("#tr"+id).css('backgroundColor','#D8F79D');
//	}
}
//从栏目文章列表中删除文章
function delArticleFromTcol(){
	if(liObj == null || liObj == ''){
		$.growlUI('请先选中栏目');
	}else{
		var tcolid = liObj.value;
		var articleid = '';
		var size = $("input[type='checkbox'][name='articleId']:checked").size();
		if(size == 0){
			$.growlUI('请先选择文章');
		}else{
			$("input[type='checkbox'][name='articleId']:checked").each(function(i,u){
				articleid += ',' + $(this).val();
			});
			$.ajax({
				url:'delArticleFromTcol',
				type:'post',
				dataType:'json',
				data:{'tcolId':tcolid,'articleIdStr':articleid},
				success:function(data){
					if(data > 0){
						$.growlUI('已成功解除关联');
						selectTree(liObj);
						if($("#allCk") != undefined)
							$("#allCk").attr('checked',false);
					}else{
						$.growlUI('操作失败');
					}
				},
				error:function(msg){
					$.growlUI('出错了');
				}
			});
		}
	}
}
//审核文章
function updateArticleCheck(type){
	var size = $("input[type='checkbox'][name='articleId']:checked").size();
	if(size > 0){
		var arid = '';
		$("input[type='checkbox'][name='articleId']:checked").each(function(){
			arid += ',' + $(this).val();
		});
		$.ajax({
			url:'checkArticle',
			type:'post',
			dataType:'json',
			data:{'articleid':arid,'check':type},
			success:function(data){
				$.growlUI('文章已审核');
				$("#allCk").attr("checked",false);
				queryTcolSource(1);
			},
			error:function(msg){
				$.growlUI('出错');
			}
		});
	}else{
		$.growlUI('请选择文章');
	}
}


///更改文章为删除状态
function updateArticleForDel(){
	var size = $("input[type='checkbox'][name='articleId']:checked").size();
	if(size > 0){
		var aid = '';
		$("input[type='checkbox'][name='articleId']:checked").each(function(i,u){
			aid += ',' + $(this).val();
		});
//		alert(aid);
		$.ajax({
			url:'updateArticleForDelete',
			type:'post',
			data:{'articleId':aid,'type':1},
			dataType:'json',
			success:function(data){
				if(data > 0){
					$.growlUI('已删除到回收站');
					$("#allCk").attr('checked',false);
					selectTree(liObj);
				}else{
					$.growlUI('删除失败');
				}
			},
			error:function(msg){
				$.growlUI('删除出现错误');
			}
		});
		
	}else{
		$.growlUI('请选择文章');
	}
}
///批量修改模板
function updateTemplate(){
	var aid = $("input[type='checkbox'][name='articleId']:checked").size();
	if(aid > 0){
		
		var kdialog = KindEditor.dialog({
			width : 400,
			height: 200,
			title : '模板列表',
			body : '<div id="template_source_div" style="padding:10px;height:150px;overflow:auto;overflow-x:hidden;"></div>',
			shadowMode:true,
			closeBtn : {
				name : '关闭',
				click : function(e) {
					kdialog.remove();
				}
			},
			yesBtn : {
				name : '确定',
				click : function(e) {
					
						var aid = '';
						$("input[type='checkbox'][name='articleId']:checked").each(function(){
							aid += ',' + $(this).val();
						});
						
						$.ajax({
							url:'updateTemplateEntityForArticle',
							type:'post',
							dataType:'json',
							data:{'articleId':aid,'tempid':$("#templateid").val(),'tcolid':liObj.value},
							success:function(data){
								if(data > 0){
									$.growlUI('修改成功');
									kdialog.remove();
									$("#allCk").attr('checked',false);
									$("input[type='checkbox'][name='articleId']:checked").each(function(){
										$(this).attr('checked',false);
									});
								}else{
									$.growlUI('修改失败');
								}
							},
							error:function(msg){
								$.growlUI('出错');
							}
						});
				}
			},
			noBtn : {
				name : '取消',
				click : function(e) {
					kdialog.remove();
				}
			}
		});
		
		$.ajax({
			url:'templateEntitySource',
			type:'post',
			dataType:'json',
			success:function(data){
				var html = '<select id="templateid">';
				$.each(data,function(i,u){
					html += '<option value="'+u.id+'">'+u.fname+'</option>';
				});
					html += '</select>';
					$("#template_source_div").html(html);
			},
			error:function(msg){
				$.growlUI('模板加载出错');
			}
		});
	}else{
		$.growlUI('请选择文章');
	}
}

///移动
function moveArticleTcol(local){
	var aid = $("input[type='checkbox'][name='articleId']:checked").size();
	if(aid == 0){
		$.growlUI('请先选中文章');
	}else{

		
		var webid = $("#select_web").val(),webtitle = $("#select_web").find(':selected').text();
		var html = '';
		var divS = '<div id="tcol_dataGrid" style="padding:10px;height:400px;overflow:auto;overflow-x:hidden;">';
		var divE = '</div>';
	
		$.ajax({
			url:'websiteinfoSource',
			type:'post',
			dataType:'json',
			success:function(data){
					html += '选择网站:';
					html += '<select id="linkColumn_web" onchange="TcolunmSource(this,\''+local+'\')" style="width:150px;font-size:14px;color:#5E5E5E;margin-top:-3px;" ><option value="" disabled="disabled" selected="selected">----站点列表----</option>';
				$.each(data,function(i,u){
					if(webid != '' && webid != null){
						if(u.id == webid){
							html += '<option value="'+u.id+'" selected="selected">'+u.ftitle+'</option>';
						}else{
							html += '<option value="'+u.id+'">'+u.ftitle+'</option>';
						}
					}else{
						html += '<option value="'+u.id+'">'+u.ftitle+'</option>';
					}
				});
				html += '</select><input id="C_WEB_NAME" type="text" onkeyup="extendArticle.addDivPanel(this,\'TcolunmSource(this,null,true)\')" onblur="extendArticle.delDivPanel()"  style="margin-left:-150px;font-size:14px; position: relative;width:130px;"/>';
			
				if(webid != '' && webid != null){
					$.ajax({
						url:'tcolunmSource',
						type:'post',
						data:{'webid':webid,'type':0},
						dataType:'json',
						success:function(data){
							html += divS;
							html +=	$.fn.simpleTree(data,local,true,webtitle,'link');
							html += divE;
							moveClick(html,liObj != null?liObj.value:null);
						},
						error:function(msg){
							$.growlUI('栏目加载出错');
						}
					});
				}else{
					html += divS + divE;
					if(liObj != null && liObj != undefined){
						moveClick(html,liObj.value);
					}else{
						moveClick(html,0);
					}
						
				}	
			},
			error:function(msg){
				$.growlUI('网站数据加载出错');
			}
		});
	}
}



/*关联栏目到网站*/
function moveColummForSite(local){
	if (liObj != null) {
		_waiting._show('正在加载.....');
		
		var webid = $("#select_web").val(), webtitle = $("#select_web").find(
				':selected').text();
		var html = '';
		var divS = '<div id="tcol_dataGrid" style="padding:10px;height:250px;overflow:auto;overflow-x:hidden;">';
		var divE = '</div>';
		
		$.ajax({
					url : 'websiteinfoSource',
					type : 'post',
					dataType : 'json',
					success : function(data) {
						html += '选择网站:';
						html += '<select id="linkColumnToWeb_web" onchange="TcolunmSource(this,\''
								+ local
								+ '\')" style="width:150px;font-size:14px;color:#5E5E5E;margin-top:-3px;" ><option value="" disabled="disabled" selected="selected">----站点列表----</option>';
						$.each(data, function(i, u) {
							if (webid != '' && webid != null) {
								if (u.id == webid) {
									html += '<option value="' + u.id
											+ '" selected="selected">'
											+ u.ftitle + '</option>';
								} else {
									html += '<option value="' + u.id + '">'
											+ u.ftitle + '</option>';
								}
							} else {
								html += '<option value="' + u.id + '">'
										+ u.ftitle + '</option>';
							}
						});
						html += '</select><input id="C_WEB_NAME" type="text"  onkeyup="extendArticle.addDivPanel(this,\'TcolunmSource(this,null,true)\')" onblur="extendArticle.delDivPanel()"  style="margin-left:-150px;font-size:14px; position: relative;width:130px;"/>';

						if (webid != '' && webid != null) {
							$.ajax({
								url : 'tcolunmSource',
								type : 'post',
								data : {
									'webid' : webid,'type':0
								},
								dataType : 'json',
								success : function(data) {
									html += divS;
									html += $.fn.simpleTree(data, local, true,
											webtitle, 'link');
									html += divE;
									moveColumnForSiteClick(html, liObj.value);
								},
								error : function(msg) {
									$.growlUI('栏目加载出错');
								}
							});
						} else {
							html += divS + divE;
							if (liObj != null && liObj != undefined) {
								moveColumnForSiteClick(html, liObj.value);
							} else {
								moveColumnForSiteClick(html, 0);
							}

						}
						_waiting._hide();
					},
					error : function(msg) {
						_waiting._hide();
						$.growlUI('网站数据加载出错');
					}
				});
	} else {
		$.growlUI("请选择栏目");
	}
}
function moveColumnForSiteClick(html,oldTcolid){
	//模板
	var kdialog = KindEditor.dialog({
		width : 550,
		height : 350,
		title : '栏目列表',
		body : '<div  style="padding:10px;overflow:auto;overflow-x:hidden;">'
				+ html + '</div>',
		shadowMode : true,
		closeBtn : {
			name : '关闭',
			click : function(e) {
				kdialog.remove();
			}
		},
		yesBtn : {
			name : '确定',
			click : function(e) {
				var ckSize = $(	"input[type='checkbox'][name='columnId']:checked").size();
				if (ckSize > 0) {
					var column = '';
					$("input[type='checkbox'][name='columnId']:checked").each(
							function() {
								column += ';' + $(this).val();
							});
					e.disabled = true;
					$.ajax({
						url:'moveColumnForSite',
						type:'post',
						dataType:'json',
						data:{'targetCol':liObj.value,'colIdStr':column},
						success:function(data){
							if(data > 0){
								$.growlUI('关联成功');
								kdialog.remove();
							}else{
								$.growlUI('关联失败');
							}
						},
						error:function(msg){
							$.growlUI('保存出错');
						}
					});
				} else {
					$.growlUI('请选择关联到的栏目！');
				}
			}
		},
		noBtn : {
			name : '取消',
			click : function(e) {
				kdialog.remove();
			}
		}
	});
}




/** 已关联栏目查询 */
function associationTcolQuery(rc){
	var aid = $("input[type='checkbox'][name='articleId']:checked").val();
	if(aid != undefined && aid != ''){
		var kdialog = KindEditor.dialog({
			width : 450,
			height: 400,
			title : '已关联栏目列表',
			body : '<div id="association_source_div" style="padding:10px;height:300px;overflow:auto;overflow-x:hidden;"></div>',
			shadowMode:true,
			closeBtn : {
				name : '关闭',
				click : function(e) {
					kdialog.remove();
				}
			},
			yesBtn : {
				name : '解除关联',
				click : function(e) {
					var tcolids = $("input[type='checkbox'][name='tcolId']:checked").size();
					if(tcolids > 0){
						var tids = '';
						$("input[type='checkbox'][name='tcolId']:checked").each(function(){
							tids += ',' + $(this).val();
						});
						
						$.ajax({
							url:'delArticleFromTcol',
							type:'post',
							dataType:'json',
							data:{'tcolId':tids,'articleIdStr':aid},
							success:function(data){
								$.growlUI('已解除关联');
								$("#allCk").attr("checked",false);
								associtionSource(aid,rc);
							},
							error:function(msg){
								$.growlUI('出错');
							}
						});
					}else{
						$.growlUI('请选中栏目');
					}
				}
			},
			noBtn : {
				name : '取消',
				click : function(e) {
					kdialog.remove();
				}
			}
		});
		
		associtionSource(aid,rc);
	}else{
		$.growlUI('请先选中文章');
	}
}
function associtionSource(aid,rc){
	$.ajax({
		url:'associationTcolQuery',
		type:'post',
		dataType:'json',
		data:{'arid':aid},
		success:function(data){
			var html = '';
			$.each(data.webList,function(j,n){
						html += '<font size="1">所属网站：</font><strong>'+n.ftitle+'</strong><br/>';
				$.each(data.tcolList,function(i,u){
					if(n.id == u.fsiteid){
						html += '<div onclick="selectTcolCk('+u.id+')" id="div_li"><img src="'+rc+'/images/tree/folder.gif" align="middle"/>'+ u.fcolumnname +'<input type="checkbox" id="tcol_ckbox_'+u.id+'" style="float:right;margin-top:5px;" name="tcolId" value="'+u.id+'"/></div>';
					}
				});
			});
			$("#association_source_div").html(html);
		},
		error:function(smg){
			$.growlUI('出错');
		}
	});
}
function selectTcolCk(tid){
	if(document.getElementById('tcol_ckbox_'+tid).checked){
		document.getElementById('tcol_ckbox_'+tid).checked = false;
	}else{
		document.getElementById('tcol_ckbox_'+tid).checked = true;
	}
}
function queryChange(id){
//	if(id == 3){
//		$("input[type='text'][name='aname']").hide();
//		$("#query_class").hide();
//		$("#query_type").hide();
//		$("#time_panl").show();
//	}else if(id < 3){
//		$("input[type='text'][name='aname']").show();
//		$("#time_panl").hide();
//		$("#query_class").hide();
//		$("#query_type").hide();
//	}else if(id > 3){
		var classhtml='<option ></option>',typehtml = '<option ></option>';
		if($("#fclassid").html() == ''){
			$.ajax({
				url:'articleSettingSource',
				type:'post',
				dataType:'json',
				success:function(data){
					$.each(data.classSource,function(i,u){
						classhtml += '<option value="'+u.id+'">'+u.fclassname+'</option>';
					});
					$.each(data.typeSource,function(i,u){
						typehtml += '<option value="'+u.id+'">'+u.ftypename+'</option>';
					});
					$("#fclassid").html(classhtml);
					$("#ftypeid").html(typehtml);
				},
				error:function(msg){
					$.growlUI('出错');
				}
			});
//		}
//		$("input[type='text'][name='aname']").hide();
//		$("#time_panl").hide();
//		if(id == 4){ $("#query_class").show(); $("#query_type").hide();}
//		if(id == 5){ $("#query_type").show(); $("#query_class").hide();}
//		if(id == 6){ $("#query_class").show();$("#query_type").show();}
	}
}
//所有用户
function loadAllUserArr(){
	$.ajax({
		url:'loadAllUser',
		type:'post',
		dataType:'json',
		success:function(data){
			var line = '<option></option>';
			$.each(data,function(i,u){
				line += '<option value="'+u.fname+'">'+u.fname+'</option>';
			});
			$("#addPersion").html(line);
		},
		error:function(msg){
			$.growlUI('用户加载出错');
		}
	});
}

///文章导入导出
var aritcleGenneration = {
	export_article:function(type){
		var aidStr = '';
		if(type != 'all'){
			var aid = $("input[type='checkbox'][name='articleId']:checked").val();
			if(aid != undefined && aid != ""){
				$("input[type='checkbox'][name='articleId']:checked").each(function(){
					aidStr += ',' + $(this).val();
				});
			}else{
				$.growlUI('请选择文章');
				return ;
			}
		}else if(type == 'all' && liObj == null){
			$.growlUI('请选择栏目');
			return;
		}
		if(confirm('确定导出吗？')){	
			_waiting._show('正在导出文章');
			$.ajax({
				url:'articleExport',
				type:'post',
				dataType:'json',
				data:{'articleIdStr':aidStr,'tid':liObj.value},
				success:function(data){
					$.growlUI('导出成功！');
					_waiting._hide();
					aritcleGenneration._showDialog();
					aritcleGenneration.loadSource(data);
				},
				error:function(msg){
					$.growlUI('导出失败！');
					_waiting._hide();
				}
			});
		}
	},
	import_article:function(){
		if(liObj != undefined && liObj != null){
			$.ajax({
				url:'articleImport',
				type:'post',
				dataType:'json',
				data:{'type':1},
				success:function(data){
					aritcleGenneration._showDialog();
					aritcleGenneration.loadSource(data);
					aritcleGenneration.loadtempSource();
				},
				error:function(){
					$.growlUI('数据加载出错');
				}
			});
		}else{
			$.growlUI('请选择栏目');
		}
	},
	loadSource:function(data){
		var html = '';
		var dataLen = data.length;
		var txtName;
		$.each(data,function(i,u){
			txtName = data[dataLen-i-1];
		  var	line = '<div id="import_txt_id'+i+'" style="height:25px;verticle-align:middle;line-height:25px;border:1px solid #ccc;padding-left:5px;margin:3px;	">'+txtName
		  			 +'<input id="'+i+'" type="checkbox" name="txt_import" onclick="aritcleGenneration.backgroundDiv(this)" value="'+txtName.substring(0,txtName.length-4)+'" style="float:right;margin-right:5px;margin-top:6px;"/></div>';
		  html += line;
		});
		$("#txt_source_div").html(html);
	},
	delete_txt:function(){
		var txt_ck_box = $("input[type='checkbox'][name='txt_import']:checked").size();
		if(txt_ck_box > 0){
			var txt_ck_name = "";
			$("input[type='checkbox'][name='txt_import']:checked").each(function(){
				txt_ck_name += "," + $(this).val();
			});
			if(confirm('确定删除？')){
				$.ajax({
					url:'delFileForArticleSource',
					type:'post',
					dataType:'json',
					data:{'fileNameStr':txt_ck_name},
					success:function(data){
						if(data.res > 0){
							$.growlUI('数据文件已删除');
							aritcleGenneration.loadSource(data.txtList);
						}else{
							$.growlUI('数据文件删除失败');
						}
					},
					error:function(){
						$.growlUI('删除出错');
					}
				});
			}
		}else{
			$.growlUI('请选中删除的数据文件');
		}
	},
	_showDialog:function(){
		var kdialog = KindEditor.dialog({
			width : 450,
			height: 400,
			title : '文章导出数据列表',
			body : '<div id="txt_source_div" style="padding:10px;height:300px;overflow:auto;overflow-x:hidden;"></div>',
			shadowMode:true,
			closeBtn : {
				name : '关闭',
				click : function(e) {
					kdialog.remove();
				}
			},
			yesBtn : {
				name : '导入',
				click : function(e) {
					var sourceid = $("input[type='checkbox'][name='txt_import']:checked").size();
					if(sourceid > 0){
						_waiting._show('正在导人文章');
						
						var sourceName = "";
						$("input[type='checkbox'][name='txt_import']:checked").each(function(){
							sourceName += ',' + $(this).val();
						});
						$.ajax({
							url:'articleImport',
							type:'post',
							dataType:'json',
							data:{'type':2,'txtNameStr':sourceName,'tcolId':liObj.value,'tempId':$("#_import_templateid").val()},
							success:function(data){
								if(data > 0){
									$.growlUI('数据导入成功');
									queryTcolSource(1);
									_waiting._hide();
								}else{
									$.growlUI('数据导入失败');
									_waiting._hide();
								}
							},
							error:function(msg){
								$.growlUI('数据导入出错');
								_waiting._hide();
							}
						});
					}else{
						$.growlUI('请选择数据文件');
					}
				}
			},
			noBtn : {
				name : '删除',
				click : function(e) {
					aritcleGenneration.delete_txt();
				}
			}
		});
	},
	backgroundDiv:function(obj){
		var div_id = obj.id;
		if(obj.checked){
			$("#import_txt_id"+div_id).css("background","#ccc");
		}else{
			$("#import_txt_id"+div_id).css("background","#ffffff");
		}
	},
	loadtempSource:function(){
		var html = '';
		$.ajax({
			url:'templateEntitySource',
			type:'post',
			dataType:'json',
			success:function(data){
					html += '<br/>选择默认模板：<select id="_import_templateid">';
					html += '<option value="">使用原模板</option>';
				$.each(data,function(i,u){
					html += '<option value="'+u.id+'">'+u.fname+'</option>';
				});
					html += '</select>';
					$("#txt_source_div").append(html);	
			},
			error:function(msg){
				 $.growlUI("模板加载出错");
			}
		});
	}
};